#ifndef IBUNDLECONTEXT_H
#define IBUNDLECONTEXT_H

#include "IBundle.h"
#include "IService.h"
#include "AutoPtr.h"
#include <QHash>
#include <QString>
#include <QVariant>
#include <QUrl>
#include <QSharedPointer>
#include <QFileInfo>

#include "BundleFramework_global.h"

#include "BundleEvent.h"
#include "ServiceException.h"
#include "ServiceReference.h"
#include "ServiceRegistration.h"

#include "hmpbundleframe_global.h"


class IServiceReference;
class IServiceRegistration;

class IBundleContext
{
public:
    typedef AutoPtr<IBundleContext> Ptr;

    IBundleContext()
    {
    }

    virtual ~IBundleContext()
    {
    }

    virtual void start(IBundleContext::Ptr pContext) = 0;

    virtual void stop(IBundleContext::Ptr  pContext) = 0;

    virtual IBundle* installBundle(const char* location, bool bCopyBundle = false) = 0;

    virtual bool startBundle(IBundle::Ptr pBundle) = 0;

    virtual bool stopBundle(IBundle::Ptr pBundle) = 0;

    virtual IServiceRegistration registerService(const char* clazzes, IService* Service) = 0;

    virtual IServiceReference getServiceReference(const char* clazze) = 0;

    virtual IService::Ptr getService(const IServiceReference& reference) = 0;

    QVariant getProperty(const QString& key) const;
    std::string getProperty(const std::string& key) const;
    QSharedPointer<Bundle> getPlugin() const;
    Bundle* getBundle() const;
    QSharedPointer<Bundle> getPlugin(long id) const;
    QList<QSharedPointer<Bundle> > getPlugins() const;
    void getBundles(std::vector<Bundle*>& bundles ) const;
    ServiceRegistration registerService(const QStringList& clazzes, QObject* service, const Dictionary& properties = Dictionary());
    ServiceRegistration registerService(const std::list<std::string>& clazzes, QObject* service, const Dictionary& properties);
    ServiceRegistration registerService(const char* clazz, QObject* service, const Dictionary& properties = Dictionary());
    template<class S>
    ServiceRegistration registerService(QObject* service, const Dictionary& properties = Dictionary());
    QList<ServiceReference> getServiceReferences(const QString& clazz, const QString& filter = QString());
    void getServiceReferences(const std::string& clazz, std::list<ServiceReference> results,const std::string& filter = std::string());
    template<class S>
    QList<ServiceReference> getServiceReferences(const QString& filter = QString());
    ServiceReference getServiceReference(const QString& clazz);
    ServiceReference getServiceReference(const std::string& clazz);
    template<class S>
    ServiceReference getServiceReference();
    QObject* getService(const ServiceReference& reference);
    template<class S>
    S* getService(const ServiceReference& reference);
    bool ungetService(const ServiceReference& reference);
    QFileInfo getDataFile(const QString& filename);
    std::string pathForLibrary(const std::string& libraryName);
    QSharedPointer<Bundle> installPlugin(const QUrl& location, QIODevice* input = 0);
    Bundle* installBundle(const std::string& location, bool bCopyBundle = false);
    bool uninstallBundle(Bundle *pBundle);
    bool resolveBundle(Bundle *pBundle);
    bool startBundle(Bundle *pBundle);
    bool stopBundle(Bundle *pBundle);
    bool connectPluginListener(const QObject* receiver, const char* slot, Qt::ConnectionType type = Qt::QueuedConnection);
    void disconnectPluginListener(const QObject* receiver, const char* slot = 0);
    bool connectFrameworkListener(const QObject* receiver, const char* slot, Qt::ConnectionType type = Qt::QueuedConnection);
    void disconnectFrameworkListener(const QObject* receiver, const char* slot = 0);
    void connectServiceListener(QObject* receiver, const char* slot,
                                const QString& filter = QString());
    void disconnectServiceListener(QObject* receiver, const char* slot);

private:

};

#endif // IBUNDLECONTEXT_H
